getLineWelderBoardInfo = function () {
  return new Promise((resolve, reject) => {
    eapGet(
      '/api/LineWelder/GetProductionInfos',
      (res) => {
        var welderStatus = []
        var welderDatas = []
        if (res.success) {
          // console.log(`getLineWelderBoardInfo=>`, res)

          if (res.result && res.result.length > 0) {
            let index = 0
            res.result.forEach((m) => {
              // console.log(`m:`,m);
              let welderIndex = Math.floor(index / 2) + 1
              welderStatus.push({
                index: index,
                chartId1: `pieChart${index}`,
                chartId2: `pieChart${index + 100}`,
                chartId3: `pieChart${index + 200}`,
                equipmentName: `${m.eapEquipmentName}`,
                status: m.status,
                ok: m.okString,
                ng: m.ngString,
                okRate: m.okRate,
                errorRate: m.errorRate,
                utilRate: m.utilityRate,
              })

              welderDatas.push({
                index: index + 1,
                equipmentCode: m.equipmentCode + ':' + m.line,
                manualFluxTempSet: m.manualFluxTempSet,
                preheatBasePlateTempSet: m.preheatBasePlateTempSet,
                complexBorderTempSet: m.complexBorderTempSet,
                solderBasePlateSet: m.solderBasePlateSet,
                holdingBasePlatSet1: m.holdingBasePlatSet1,
                holdingBasePlatSet2: m.holdingBasePlatSet2,
                holdingBasePlatSet3: m.holdingBasePlatSet3,
                lampPowerSet1: m.lampPowerSet1,
                lampPowerSet2: m.lampPowerSet2,
              })
              index++
            })
          }

          // console.log(`LineWelder welderStatus:`, welderStatus)
          // console.log(`LineWelder welderDatas:`, welderDatas)
        }
        resolve({
          welderStatus,
          welderDatas,
        })
      },
      (e) => {
        reject(e)
      }
    )
  })
}

getOverlapWelderBoardInfo = function () {
  return new Promise((resolve, reject) => {
    eapGet(
      '/api/OverlapWelder/GetProductionInfos',
      (res) => {
        var welderStatus = []
        if (res.success) {
          // console.log(`getOverlapWelderBoardInfo=>`, res)

          if (res.result && res.result.length > 0) {
            let index = 0
            res.result.forEach((m) => {
              welderStatus.push({
                index: index,
                chartId1: `pieOvChart${index}`,
                chartId2: `pieOvChart${index + 100}`,
                chartId3: `pieOvChart${index + 200}`,
                equipmentName: `${m.eapEquipmentName}`,
                status: m.status,
                ok: m.okCount,
                ng: m.ngCount,
                okRate: m.okRate,
                errorRate: m.errorRate,
                utilRate: m.utilityRate,
              })

              index++
            })
          }

          // console.log(`OverlapWelder welderStatus:`, welderStatus)
        }
        resolve(welderStatus)
      },
      (e) => {
        reject(e)
      }
    )
  })
}

getOverlapWelderPowerBoardInfo = function () {
  return new Promise((resolve, reject) => {
    eapGet(
      '/api/LineWelder/GetProductionPowerInfos',
      (res) => {
        var powerStatus = {}
        if (res.success) {
          // console.log(`getLineWelderPowerBoardInfo=>`, res)

          if (res.result && res.result.length > 0) {
            powerStatus = {
              names: res.result.map((m) => m.eapEquipmentName),
              powers: res.result.map((m) => m.power),
              perPowers: res.result.map((m) => m.perProductPower),
            }
          }

          console.log(`LineWelder powerStatus:`, powerStatus)
        }

        resolve(powerStatus)
      },
      (e) => {
        reject(e)
      }
    )
  })
}

/**
 * @description 无限滚动功能
 * @author 杨云军
 * @date 2023/05/27 07:43:18
 * @param {any} element 父元素
 * @param {any} direction 滚动方向: 1 横向, 2 纵向
 * @param {number} rowCount 行元素数量
 * @param {number} minUnitCount 最少行或者列元素数量
 * @param {number} elementHeight 元素高度
 * @returns
 *
 */
function scrollChart(element, direction, rowCount, minUnitCount, elementHeight) {
  var list = document.querySelector(element)
  var childrenLength = list.children.length
  if (childrenLength === 0) {
    return
  }
  if (minUnitCount >= childrenLength) {
    return
  }

  // 深度克隆子元素
  function cloneItems() {
    for (let i = 0; i < rowCount; i++) {
      const element = list.children[i].cloneNode(true)
      list.appendChild(element)
    }

    for (let i = 0; i < rowCount; i++) {
      list.removeChild(list.children[0])
    }
  }

  let rows = Math.ceil(childrenLength / rowCount)
  let animateInterval = (rows - 3) * 5000
  let height = elementHeight * (rows - 3)

  const keyframes = [{ transform: direction === 1 ? `translateX(-${height}px)` : `translateY(-${height}px)` }]

  const options = {
    // 动画执行次数
    iterations: Infinity,
    // 动画开始时间点
    iterationStart: 0,
    // 动画开始之前的延迟
    delay: 0,
    // 动画结束之后的延迟
    endDelay: 0,
    // 动画是否在下一周期逆向播放
    direction: 'normal',
    // 动画时长
    duration: animateInterval,
    // 动画前后保持的状态
    fill: 'forwards',
    // 动画缓动类型
    easing: 'ease-in-out',
  }

  list.animate(keyframes, options)
}

/**
 * @description 无限滚动功能
 * @author 杨云军
 * @date 2023/05/27 07:43:18
 * @param {any} element 父元素
 * @param {any} direction 滚动方向: 1 横向, 2 纵向
 * @param {number} rowCount 行元素数量
 * @param {number} minUnitCount 最少行或者列元素数量
 * @param {number} elementHeight 元素高度
 * @returns
 *
 */
function scrollTable(element, direction, rowCount, minUnitCount, elementHeight) {
  var list = document.querySelector(element)
  var childrenLength = list.children[0].children.length
  if (childrenLength === 0) {
    return
  }
  if (minUnitCount >= childrenLength) {
    return
  }

  let rows = Math.ceil(childrenLength / rowCount)
  // console.log(`scrollTable rows: `, rows)
  let animateInterval = (rows - 5) * 1000
  if (animateInterval < 10000) {
    animateInterval = 10000
  }
  let height = elementHeight * (rows - 5)

  const keyframes = [{ transform: direction === 1 ? `translateX(-${height}px)` : `translateY(-${height}px)` }]

  const options = {
    // 动画执行次数
    iterations: Infinity,
    // 动画开始时间点
    iterationStart: 0,
    // 动画开始之前的延迟
    delay: 0,
    // 动画结束之后的延迟
    endDelay: 0,
    // 动画是否在下一周期逆向播放
    direction: 'normal',
    // 动画时长
    duration: animateInterval,
    // 动画前后保持的状态
    fill: 'forwards',
    // 动画缓动类型
    easing: 'ease-in-out',
  }

  list.animate(keyframes, options)
}
